<?php

namespace app\common\model;

/**
 * Description of BlacklistModel
 *
 * @author DevPHP
 * @version 2018-4-10
 */
class BlacklistModel {

    static $table = 'system_blacklist';

    /**
     * 检测黑名单
     * @param type $content
     * @return integer 返回禁用时间
     */
    public function check($content) {
        $where = ['content' => $content, 'status' => 1];

        $data = db(self::$table)->where($where)->field('status,expire_unixtime,reason')->find();
        if (isset($data['status']) && ($data['expire_unixtime'] < time())) {
            db(self::$table)->where($where)->setField('status', 0);
            $data = false;
        }
        return $data;
    }

    public function addItem($content, $expire, $category, $reason, $admin_id) {
        $data = [
            'content' => $content,
            'expire_unixtime' => time() + $expire,
            'category_name' => $category,
            'reason' => $reason,
            'status' => 1,
            'admin_id' => $admin_id,
        ];
    }

    public function removeItems($ids) {
        $where['id'] = ['in', $ids];
        db(self::$table)->where($where)->delete();
    }

}
